package com.caigou.modules.home.repository

import com.caigou.comm.base.bean.Banner
import com.caigou.comm.base.bean.HttpResult
import com.caigou.modules.home.bean.PrizeTimeBean
import com.caigou.modules.home.bean.PrizeBean
import com.caigou.modules.home.network.HttpHomeService
import dagger.hilt.android.scopes.ActivityRetainedScoped
import kotlinx.coroutines.flow.Flow
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import javax.inject.Inject

/**
 * @author #Suyghur.
 * Created on 2021/09/16
 */
@ActivityRetainedScoped
class HomeRepository @Inject constructor() {

    fun getBanners(): Flow<HttpResult<MutableList<Banner>>> {
        return HttpHomeService.service.getBanners()
    }

    fun getPrizeResult(type: Int, userId: String): Flow<HttpResult<PrizeBean>> {
        return HttpHomeService.service.getPrizeResult(type, userId)
    }

    fun getHistoryPrizeList(type: Int, year: Int): Flow<HttpResult<MutableList<PrizeBean>>> {
        return HttpHomeService.service.getHistoryPrizeList(type, year)
    }

    fun getOpenPrizeTime(): Flow<HttpResult<MutableList<PrizeTimeBean>>> {
        return HttpHomeService.service.getOpenPrizeTime()
    }

    fun setMiStatus(period: Int, userId: String, type: Int, status: Int): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("period", period)
        jsonObject.put("userId", userId)
        jsonObject.put("type", type)
        jsonObject.put("status", status)
        val body = jsonObject.toString().toRequestBody()
        return HttpHomeService.service.setMiStatus(body)
    }

}